import React from 'react';
import React from 'react';
import { Button, Table } from 'packages/ui-shared/src/atoms';
import { Space } from 'packages/ui-shared/src/molecules';
import { PlusOutlined, EditOutlined, DeleteOutlined } from 'packages/ui-shared/src/icons';

interface ScheduleTableProps<T> {
  title: string;
  data: T[];
}

const ScheduleTable = <T extends { id: string }>({ title, data }: ScheduleTableProps<T>) => {
  // 根据数据自动生成列定义
  const generateColumns = () => {
    if (data.length === 0) return [];
    
    const firstItem = data[0];
    const columns = Object.keys(firstItem).map(key => ({
      title: key,
      dataIndex: key,
      key: key,
    }));
    
    // 添加操作列
    columns.push({
      title: '操作',
      key: 'action',
      render: (_, record) => (
        <Space size="middle">
          <Button type="text" icon={<EditOutlined />}>编辑</Button>
          <Button type="text" danger icon={<DeleteOutlined />}>删除</Button>
        </Space>
      ),
    });
    
    return columns;
  };

  return (
    <div>
      <div style={{ marginBottom: 16, display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <h3>{title}</h3>
        <Button type="primary" icon={<PlusOutlined />}>新增</Button>
      </div>
      <Table columns={generateColumns()} dataSource={data} rowKey="id" />
    </div>
  );
};


export default ScheduleTable;